package com.study.flink.java.day04_async.async_io.es;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.AsyncDataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.concurrent.TimeUnit;

/**
 * ElasticSearch异步IO请求，提高程序执行效率
 */
public class AsyncQueryFromEs {

    public static void main(String[] args) throws Exception{
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        // env.setParallelism(1);
        DataStreamSource<String> stream = env.socketTextStream("node02", 8888);
        SingleOutputStreamOperator<Tuple2<String, String>> soso = AsyncDataStream.unorderedWait(
                stream, new AsyncEsRequest(), 0, TimeUnit.MILLISECONDS);
        soso.print();
        env.execute("AsyncQueryFromEs");
    }

}
